﻿using Data.Core.Models;
using Data.Service;
using MVCAngularJS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace MVCAngularJS.Controllers
{
    public class BlogController : ApiController
    {
        public IEnumerable<BlogModel> Get()
        {
            var blogService = new BlogService();
            var blogs = blogService.GetAllBlogs().Select(c=> new BlogModel { //不要直接使用entity返回，先转成model
                BlogId = c.BlogId,
                Name = c.Name
            }).ToList();
            return blogs;
        }

        [HttpGet]
        public void Delete(int blogId)
        {
            if(blogId == 0)
            {
                return;
            }
            var blogService = new BlogService();
            var blog = blogService.GetBlogById(blogId);
            blogService.Delete(blog);
        }
    }
}
